package com.pactera.madp.cp.service.sync.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pactera.madp.cp.api.entity.sync.MaMarketingLeadDetailsEntity;
import com.pactera.madp.cp.mapper.sync.MaMarketingLeadDetailsMapper;
import com.pactera.madp.cp.service.sync.MaMarketingLeadDetailsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @title 经理视图 -> 营销线索明细 业务接口实现
 * @date 2022-05-19
 * @author Deming.Chang
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MaMarketingLeadDetailsServiceImpl extends ServiceImpl<MaMarketingLeadDetailsMapper, MaMarketingLeadDetailsEntity> implements MaMarketingLeadDetailsService {

    @Override
    public int summaryAndSave(String maDate) {
        return baseMapper.summaryAndSaveByMaDate(maDate);
    }

    @Override
    public int removeHisData(String maDate, int offset) {
        String date = DateUtil.format(DateUtil.offsetDay(DateUtil.parse(maDate), offset), DatePattern.NORM_DATE_PATTERN);
        return baseMapper.delete(Wrappers.<MaMarketingLeadDetailsEntity>query().lambda().le(MaMarketingLeadDetailsEntity::getMaDate, date));
    }

}

